﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CoreData;
using ActionServices;
using Helper;

namespace ZidoniCMS.Controllers
{
    public class EmailController : BaseController
    {
        //
        // GET: /Email/
        public EmailController(IEmailListActionService _emaillist, IEmailTemplateActionService _emailtemplate)
            :base(_emaillist, _emailtemplate){}

        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// Partial View dùng để người dùng đăng ký nhận tin tức qua mail
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult _NewLesterAdd() {
            return PartialView();
        }
        /// <summary>
        /// Action dùng để người dùng đăng ký nhận tin tức qua mail
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult NewLesterAdd(EmailList model)
        {
            var exist = EmailListService.GetOneByLINQ(x => x.Email == model.Email);
            bool checkEmail = ValidateData.CheckEmail(model.Email);
            if (exist == null && model.Email.Equals("") == false && checkEmail == true)
            {
                EmailListService.Save(model);
                model = EmailListService.GetByID(model.ID);
                return Json(model, JsonRequestBehavior.AllowGet);
            }
            else if (exist != null) {
                return Content("exist");
            }
            else
            {
                return Content("fail");
            }
        }

    }
}
